/*author:linsengzs*/

var igoObj = {};
igoObj.getId = function(objId) {
    return typeof (objId) == "Object" ? objId : document.getElementById(objId);
}
//init/bind control
$(document).ready(function() {
    $("#login").click(function() {
        igoObj.login();
    })
    $("#register").click(function() {
        window.location.href = '/h5/account/reg';
    })
    $("#verify").css('border-bottom', 'none');

    $("#uname").blur(function() {
        if ($("#uname").val().match(/^1[34578]{1,1}[0-9]{9,9}$/)) {
            //$("#uname").attr('value',$("#ctmname").val())
        }
    })

    $("#igo_reg").click(function() {
        igoObj.reg();
    })

    $("#changeVerify").click(function() {
        var url = '../ajax/changeverify.ajax.php';
        var result = $.ajax({
            url: url,
            asyn: false,
            dataType: 'json',
            type: 'post',
            success: function(result) {
                if (result.status == 1) {
                    $("#changeVerify").prev().attr("src", 'data:image/png;base64,' + result.desc);
                }
            }
        });
    })
    $("#barea").change(function() {
        changeArea();
    })
    $("#area").change(function() {
        if ($("#area").prev().html() != '请选择城市') {
            $("#area").prev().removeClass('c_gray');
        } else {
            $("#area").prev().addClass('c_gray');
        }
    })
    $("#registerback").click(function() {
        if (document.referrer == '') {
            location.href = 'login.html';
        } else {
            location.href = document.referrer;
        }
    })
})

igoObj.navigateToNew = function(p, arg) {
    location.href = p + "" + (typeof (arg) == "undefine" ? "" : "?" + arg);
}

//手机注册
igoObj.reg_tab = function(tabIdShow, tabIdHide)
{
    this.getId('reg_' + tabIdHide).style.display = 'none';
    this.getId('reg_' + tabIdShow).style.display = 'block';
    $(".reg_tab_" + tabIdShow).addClass('reg_on');
    $(".reg_tab_" + tabIdHide).removeClass('reg_on');
    $("#reg_" + tabIdHide).addClass('reg_off');
    $("#reg_" + tabIdShow).removeClass('reg_off');
    
    $('#hidLoginType').val(tabIdShow === 'phonelogin' ? '0' : '1'); // 0=手机带密码登录、1=手机无密码登录
}

igoObj.findpass = function() {
    var val = $("#uname").attr('value');
    if (val != '请输入手机号' && val.match(/^1[34578]{1,1}[0-9]{9,9}$/)) {
        location.href = '/h5/account/findpwd?phone=' + val;
    } else {
        location.href = '/h5/account/findpwd';
    }

}

igoObj.sendgood_complete=function(){
	var uname 	= $('#uname').val(),
		password 	= $('#password').val(),
		verify		= $('#verify').val(),
		needcar		=$('#needcar').val();
}

igoObj.isHmlTag=function(str){
	var istag=/(<[a-zA-Z]*)|(<!)/;
	if(str.match(istag)){
		return true;
	}
	return false;
}

igoObj.showPwd=function(objid){
	var showValue=$('#'+objid).val().replace(/^[\s]+|[\s]+$/g,"");
	if(showValue=='')showValue='对不起，您还没有输入内容';
	else 
	{
		if(this.isHmlTag(showValue)){
			showValue="密码不能包含标签";
		}else{
			showValue='客官，您要查看的数据为：'+showValue;
		}
	}
	pop(showValue,'1','确定','','popclose()');
}

igoObj.reg = function() {
   var utype="phone";
	//get param
    var uname = $("#uname").val();
    upwd = $("#uregpwd").val(),
            email = $("#uemail").val(),
            ucpwd = $("#ucregpwd").val(),
            pwd = $("#regpwd").val(),
            cpwd = $("#cregpwd").val(),
            telephone = $("#telephone").val(),
            verification_code = $('#verification_code').val();
    if (utype == "phone") {
        //过滤前后空格
        telephone = telephone.replace(/^[\s]+|[\s]+$/g, "");
        verification_code = verification_code.replace(/^[\s]+|[\s]+$/g, "");
        pwd = pwd.replace(/^[\s]+|[\s]+$/g, "");
		if(!igoObj.check("telphone",telephone))return false;
		if(!igoObj.check("checkcode",verification_code))return false;

		uname=telephone;
		upwd=pwd;
		ucpwd=cpwd;
	}else{		
		if('请输入用户名' == uname||uname==''){
			igoObj.pop('请输入用户名',1,'确定','','igoObj.popclose()');
			return false;
		}
		if(!igoObj.check('email',email))return false;
	}

	if(!igoObj.check("password",upwd))return false;
	
    /*
    if ('请输入确认密码' == ucpwd || ucpwd == '') {
        pop('请输入确认密码', 1, '确定', '', 'popclose()');
        return false;
    }
    if (upwd != ucpwd) {
        pop('两次密码不一致，请确认', 1, '确定', '', 'popclose()');
        return false;
    }
    */

    api.register();
}

igoObj.findpwd = function() {
    api.findpwd();
}

igoObj.register = function() {
    var companyname = $("#companyname").val();
    areacode = $("#area").val(),
            address = $("#address").val(),
            username = $("#username").val(),
            telephone = $("#telephone").val(),
            email = $("#email").val(),
            verify = $('#verify_code').val();
    if ('请输入公司名' == companyname) {
        pop('请输入公司名', 1, '确定', '', 'popclose()');
        return false;
    }
    if ('请选择城市' == areacode) {
        pop('请选择城市', 1, '确定', '', 'popclose()');
        return false;
    }
    if ('请输入地址' == address) {
        pop('请输入地址', 1, '确定', '', 'popclose()');
        return false;
    }
    if ('请输入联系人' == username) {
        pop('请输入联系人', 1, '确定', '', 'popclose()');
        return false;
    }
    if ('请输入联系电话' == telephone) {
        pop('请输入联系电话', 1, '确定', '', 'popclose()');
        return false;
    }
    if ('请输入Email' == email) {
        pop('请输入Email', 1, '确定', '', 'popclose()');
        return false;
    }
    if (!/^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|com|gov|mil|org|edu|int|name|asia)$/.test(email))
    {
        pop('对不起，您Email输入有误', 1, '确定', '', 'popclose()');
        return false;
    }
    if ('请输入验证码' == verify || '' == verify) {
        pop('请输入验证码', 1, '确定', '', 'popclose()');
        return false;
    }
    var companylen = companyname.replace(/[^\x00-\xff]/g, "**").length;
    if (companylen > 100) {
        pop('公司名过长', 1, '确定', '', 'popclose()');
        return false;
    }
    var addresslen = address.replace(/[^\x00-\xff]/g, "**").length;
    if (addresslen > 200) {
        pop('地址过长', 1, '确定', '', 'popclose()');
        return false;
    }
    var usernamelen = username.replace(/[^\x00-\xff]/g, "**").length;
    if (usernamelen > 100) {
        pop('联系人过长', 1, '确定', '', 'popclose()');
        return false;
    }
    var emaillen = email.replace(/[^\x00-\xff]/g, "**").length;
    if (emaillen > 80) {
        pop('Email过长', 1, '确定', '', 'popclose()');
        return false;
    }

    var url = '../ajax/user/register.ajax.php';
    var param = {'companyname': companyname,
        'username': username,
        'areacode': areacode,
        'address': address,
        'email': email,
        'verify': verify,
        'telephone': telephone};
    var result = $.ajax({
        url: url,
        asyn: false,
        dataType: 'json',
        type: 'post',
        data: param,
        success: function(result) {
            if (result.status == 1) {
                location.href = result.url;
            } else if (result.status == 4) {
                pop('验证码错误', 1, '确定', '', 'popclose()');
                $('#verify_code').val('');
                $("#changeVerify").click();
                return false;
            } else {
                pop(result.desc, 1, '确定', '', 'popclose()');
                return false;
            }
        }
    });
}
igoObj.check=function(chkName,chkValue){
	if(chkName=="telphone"){
		if('请输入手机号' == chkValue|| ''==chkValue){//请输入手机号/Email/用户名
			pop('请输入手机号','1','确定','','popclose()');
			return false;
		}
		if(!chkValue.match(/^1[34578]{1,1}[0-9]{9,9}$/)){
			pop('请输入正确手机号',1,'确定','','popclose()');
			return false;
		}
	}else if(chkName=="password"){
		if('请输入密码' == chkValue || '' == chkValue){
			pop('请输入密码','1','确定','','popclose()');
			return false;
		}
		if('请输入6-12位字母加数字' == chkValue || '' == chkValue){
			pop('请输入6-12位字母加数字',1,'确定','','popclose()');
			return false;
		}
		if(chkValue.length<6 || chkValue.length>12){
			pop('密码必须在6～12位之间！',1,'确定','','popclose()');
			return false;
		}
		//if(chkValue.match(/^[0-9]*[1-9][0-9]*$/) || chkValue.match(/^[A-Za-z]+$/) || !chkValue.match(/^[A-Za-z0-9]+$/)){
		//	pop('密码由字母加数字组成！',1,'确定','','popclose()');
		//	return false;
		//}
	}else if(chkName=="checkcode"){
		if('请输入验证码' == chkValue || '' == chkValue){
			pop('请输入验证码','1','确定','','popclose()');
			return false;
		}
		if(!/^\d{6}$/.test(chkValue)){
			pop('请输入正确验证码',1,'确定','','popclose()');
			return false;
		}
	}else if(chkName=="email"){
		if('请输入您的常用邮箱' == chkValue || chkValue == ""){
			igoObj.pop('请输入您的常用邮箱',1,'确定','','igoObj.popclose()');
			return false;
		}else{
			//去除前后空格和逗号
			var email = chkValue.replace(/^[\s]+|[\s]+$/g,"").replace(/^[,]+|[,]+$/g,"");
			if(email.indexOf(";") >= 0){
				igoObj.pop('请输入有效的Email地址！',1,'确定','','igoObj.popclose()');
				return false;
			}
			//判断邮箱长度
			var emailLen = email.replace(/[^\x00-\xff]/g,"**").length;
			if(emailLen > 80){
				igoObj.pop('Email地址过长！',1,'确定','','igoObj.popclose()');
				return false;
			}
			var emailSplit = email.split(',');
			//最多可输入一个邮箱
			if(emailSplit.length > 1){
				igoObj.pop('只能输入一个Email！',1,'确定','','igoObj.popclose()');
				return false;
			}
			for(var i=0;i<emailSplit.length;i++){
				var myreg =/^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*))@([A-Za-z0-9]+[-A-Za-z0-9_]*\.)+[A-Za-z]{2,}$/;
				if(!myreg.test(emailSplit[i])){
					igoObj.pop('对不起，您的邮箱格式错误！',1,'确定','','igoObj.popclose()');
					return false;
				}
			}
		}	
	}

	return true;
}

igoObj.login = function() {
   var utype="";
	var phonecss=$("#reg_phonelogin").attr('class');
	var customcss=$("#reg_customlogin").attr('class');
	if(phonecss.indexOf("reg_off")>-1&&(customcss=='box'||customcss==null)){
		utype="custom";
	}else if(customcss.indexOf("reg_off")>-1&&(phonecss=='box'||phonecss==null)){
		utype="phone";
	}
	if('' == utype||(phonecss==null&&customcss==null)){
		pop('请选择登录类型',1,'确定','','popclose()');
		return false;
	}
	var uname 	= $('#uname').val(),
		password 	= $('#password').val(),
		verify		= $('#verify').val(),
		autoLogin   = $('#autoLogin').find('font').attr('class'),
		agreeProtocol=$('#chkProtocol').find('font').attr('class'),
		isshow		= $('#show_verify').css('display');
	if(utype=="phone"){
		if(!igoObj.check("telphone",uname))return false;
		if(!igoObj.check("password",password))return false;
		if('block' == isshow){
			if('请输入验证码' == verify){
				pop('请输入验证码','1','确定','','popclose()');
				return false;
			}
		}
		if('not' == agreeProtocol){
			pop('请查看协议同意后再继续！','1','确定','','popclose()');
			return false;
		}
	}
	else{
		uname=$('#unamenopwd').val();
		if(!igoObj.check("telphone",uname))return false;
		var verifynopwd=$('#verifynopwd').val();
		if(!igoObj.check("checkcode",verifynopwd))return false;
	}
        
    // 登录 peng.huang
    api.login();
};

//弹出层
igoObj.pop = function(msg, mtype, but1, but2, fun1, fun2) {
    //msg:文本信息
    //mtype:弹层类型	0:文字靠左显示		1:文字居中显示
    //but1:按钮一文字
    //but2:按钮二文字
    //fun1:按钮一方法
    //fun2:按钮二方法

    var top = document.body.scrollTop || document.documentElement.scrollTop;
    var h = document.body.scrollHeight > windowH ? document.body.scrollHeight : windowH;

    mtype = mtype ? mtype : 0;

    if ($('#pop')[0]) {
        var $text = $('#pop .text');
        var butInfo = but1 ? "<span onclick='" + fun1 + "'>" + but1 + "</span>" : '';
        if (mtype) {
            if (!$text.hasClass('center')) {
                $text.addClass('center');
            }
        } else {
            $text.removeClass('center');
        }

        $('#pop .text').html(msg);

        if (but2) {
            butInfo += "<span onclick=" + fun2 + ">" + but2 + "</span>";
        }

        if (butInfo) {
            if ($('#pop .op')[0]) {
                $('#pop .op').html(butInfo);
            } else {
                $('#pop .cn').append("<div class='op'>" + butInfo + "</div>");
            }
        } else {
            $('#pop .op').remove();
        }

        if (arguments.length > 2) {
            $('#pop .cn').removeClass('c2');
            $('#pop .close').remove();
        }

    } else {
        var className = "text";
        var butInfo = but1 ? "<span onclick=" + fun1 + ">" + but1 + "</span>" : '';
        if (mtype) {
            className = "text center";
        }
        if (but2) {
            butInfo += "<span onclick=" + fun2 + ">" + but2 + "</span>";
        }

        var htm = "<section id='pop'>";
        if (arguments.length <= 2) {
            htm += "<div class='cn c2'>";
            htm += "<span class='close' onclick='igoObj.popclose()' id='close_btn'></span>";
        } else {
            htm += "<div class='cn'>";
        }
        htm += "<p class='" + className + "'>" + msg + "</p>";
        if (butInfo) {
            htm += "<div class='op'>";
            htm += butInfo;
            htm += "</div>";
        }
        htm += "</div>";
        htm += "</section>";

        if (!$('#shadow')[0]) {
            htm += "<div id='shadow'></div>";
        }

        $('body').append(htm);
    }
    //该层先显示取出层的高度后再隐藏
    $('#pop').show();
    var tp = $('#pop').height();
    $('#pop').hide();
    var hb = document.documentElement.clientHeight;
    tp = (hb - tp) / 2;
    tp = tp >= 0 ? tp : 0;
    tp += top;

    $('#shadow').height(h);
    $('#pop').css('top', tp);

    $('#pop,#shadow').show();
}
//特殊弹出层
igoObj.popshow = function(name) {
    if (!$('#shadow')[0]) {
        $('body').append("<div class='shadow'></div>");
    }

    name = '.' + name;
    var top = document.body.scrollTop || document.documentElement.scrollTop;
    var h = $('body').height();
    var tp = $(name).height();
    var hb = document.documentElement.clientHeight;

    tp = (hb - tp) / 2;
    tp = tp >= 0 ? tp : 0;
    tp += top;

    $('#shadow').height(h);
    $(name).css('top', tp);

    $('#shadow,' + name).show();
}
//弹出层关闭
igoObj.popclose = function() {
    $('#pop,.pop,#shadow').hide();
}
igoObj.showMsg = function(keytype) {
    $('#chkCode').val();
    $('#divError').hide();

    api.getImgCode(keytype, function() {
        var top = document.body.scrollTop || document.documentElement.scrollTop;
        var h1 = $('body').height();
        var h2 = document.body.scrollHeight > windowH ? document.body.scrollHeight : windowH;
        var h = h1 > h2 ? h1 : h2;
        var tp = $(name).height();
        var hb = document.documentElement.clientHeight;

        tp = (hb - tp) / 2;
        tp = tp >= 0 ? tp : 0;
        tp += top;
        if (tp < 100)
            tp = 100;

        $('#igomsgshadow').height(h);
        $('#igomsg').css('top', tp);
        $('#igomsgshadow,#igomsg').show();
    });
}
//弹出层关闭
igoObj.showMsgclose = function(keytype) {
    api.getSms(keytype,function() {
        $('#igomsg,#igomsgshadow').hide();
        $('#chkCode').focus();
        $('#chkCode').attr('title', '请输入获取认证码');
        $('#chkCode').blur();
    });
}
igoObj.showDict=function(t,recObjId){
	var dictContent='';
	if(t=="cartypes"){
		dictContent +='<h3 class="ctitle">发布城市</h3>';
		dictContent +='<section class="hjobarea">';
		
		for(var ele in cartypes)
		{
			dictContent	+='<a class="bb bg_f" id="dt'+t+'_'+ele+'" onclick="change_selVal(this)" value="' + cartypes[ele]  + '">' + cartypes[ele] + '</a>';
		}
		
		dictContent +='</section>';
	}

	igoObj.pop(dictContent,1,'确定','','igoObj.popclose()');
}
function change() {
    var param = {'action': 'verify'};
    $.ajax({
        url: '../ajax/user/findpwd.ajax.php',
        dataType: 'json',
        type: 'post',
        data: param,
        success: function(result) {
            if (result.status == 1) {
                $("#verify").attr('src', 'data:image/png;base64,' + result.desc);
            }
        }
    });
}

function findpwd() {
    var ctmname = $('#ctmname').val(),
            hrname = $('#hrname').val(),
            EMail = $('#EMail').val();
    if ('请输入会员名' == ctmname && '请输入用户名' == hrname && '请输入EMail' == EMail) {
        pop('会员名,用户名和EMail均不能为空！', 1, '确定', '', 'popclose()');
        return false;
    }
    if ('请输入会员名' == ctmname) {
        pop('请输入会员名', 1, '确定', '', 'popclose()');
        return false;
    }
    if ('请输入用户名' == hrname) {
        pop('请输入用户名', 1, '确定', '', 'popclose()');
        return false;
    }
    if ('请输入EMail' == EMail) {
        pop('请输入EMail', 1, '确定', '', 'popclose()');
        return false;
    }
    var ctmnamelen = ctmname.replace(/[^\x00-\xff]/g, "**").length;
    if (ctmnamelen > 20) {
        pop('会员名过长', 1, '确定', '', 'popclose()');
        return false;
    }
    var hrnamelen = hrname.replace(/[^\x00-\xff]/g, "**").length;
    if (hrnamelen > 20) {
        pop('用户名过长', 1, '确定', '', 'popclose()');
        return false;
    }
    var EMaillen = EMail.replace(/[^\x00-\xff]/g, "**").length;
    if (EMaillen > 80) {
        pop('EMail过长', 1, '确定', '', 'popclose()');
        return false;
    }
    var url = '../ajax/user/findpwd.ajax.php';
    var param = {'ctmname': ctmname,
        'hrname': hrname,
        'EMail': EMail,
        'action': 'submit'};
    var result = $.ajax({
        url: url,
        asyn: false,
        dataType: 'json',
        type: 'post',
        data: param,
        success: function(result) {
            if (result.status == 1) {
                pop(result.desc, 1, '确定', '', 'popjump(\'' + result.back_login_url + '\')');
                return true;
            } else {
                pop(result.desc, 1, '确定', '', 'popclose()');
                return false;
            }
        }
    });
}
//忘记密码确定后跳转路径
function popjump(login_url) {
    popclose();
    window.location.href = '' + login_url + '';
}

function resetpwd() {
    var newpwd = $("#newpwd").val();
    var checkpwd = $("#checkpwd").val();
    var url = '../ajax/user/resetpwd.ajax.php';
    var param = {'newpwd': newpwd, 'checkpwd': checkpwd};
    var result = $.ajax({
        url: url,
        asyn: false,
        dataType: 'json',
        type: 'post',
        data: param,
        success: function(result) {
            if (result.status == 1) {
                location.href = result.url;
            } else {
                pop(result.desc, 1, '确定', '', 'popclose()');
                return false;
            }
        }
    });
}

function sendphonecode() {
    if ($('#timeBut').hasClass('gray')) {
        return;
    }
    var telphone = $('#telphone').val();
    var code = $("#verify_code").val();
    if ('请输入手机号' == telphone) {
        pop('请输入手机号', 1, '确定', '', 'popclose()');
        return false;
    }
    if ('请输入验证码' == code) {
        pop('请输入验证码', 1, '确定', '', 'popclose()');
        return false;
    }
    var param = {'telphone': telphone,
        'code': code,
        'type': '1',
    }

    var result = $.ajax({
        url: '../ajax/sendphonecode.ajax.php',
        asyn: false,
        dataType: 'json',
        type: 'post',
        data: param,
        success: function(result) {
            if (result.status == 1) {
                $('#timeBut').html('60秒后重新发送');
                $('#timeBut').addClass('gray');
                timeClock('timeBut');
                return true;
            } else if (result.status == 2) {
                $("#verifypic").attr('src', 'data:image/png;base64,' + result.pic)
                pop(result.desc, 1, '确定', '', 'popclose()');
            } else {
                pop(result.desc, 1, '确定', '', 'popclose()');
            }
        }
    });
}
function changeArea() {
    var barea = $('#barea').val();
    var htm = '';
    var content = '';
    content = '请选择城市';
    for (var ele in area_c) {
        if ((area_c[ele].substr(0, 2) == '01' || area_c[ele].substr(0, 2) == '02' || area_c[ele].substr(0, 2) == '04' || area_c[ele].substr(0, 2) == '05' || area_c[ele].substr(0, 2) == '06' || area_c[ele].substr(0, 2) == '33' || area_c[ele].substr(0, 2) == '34' || area_c[ele].substr(0, 2) == '35' || area_c[ele].substr(0, 2) == '36') && barea == area_c[ele]) {
            htm = '<option value="' + area_c[ele] + '">' + area_v[ele] + '</option>';
            content = area_v[ele];
        } else if ((area_c[ele].substr(0, 2) == barea.substr(0, 2)) && barea == area_c[ele] && area_c[ele].substr(2, 4) == '0000') {
            htm += '<option>请选择城市</option>';
        } else if (area_c[ele].substr(0, 2) == barea.substr(0, 2)) {
            htm += '<option value="' + area_c[ele] + '">' + area_v[ele] + '</option>';
        }
    }
    if ($("#barea").prev().html() != '请选择省份') {
        $("#barea").prev().removeClass('c_gray');
        $("#area").prev().addClass('c_gray');
    } else {
        $("#barea").prev().addClass('c_gray');
    }
    if ('' == htm) {
        htm = '<option>请选择城市</option>';
        $("#area").prev().addClass('c_gray');
    }
    if (content == '上海' || content == '北京' || content == '深圳' || content == '重庆' || content == '天津' || content == '香港' || content == '澳门' || content == '台湾' || content == '国外') {
        $("#area").prev().removeClass('c_gray');
    }
    $('#area').prev().html(content);
    $('#area').html(htm);
}
$('.bb select ').change(function() {//下拉框取值
    var v = '';
    $(this).find('option').each(function() {
        if ($(this).attr('selected') == true) {
            v = $(this).html();
            return false;
        }
    });
    $(this).siblings().html(v);
});

$("input[type='text'],textarea").each(function() {//自动填充Input框
    addInput($(this));
}).focus(function() {
    if ($(this).next().attr('type') == 'password') {
        $(this).hide();
        $(this).next().show().focus().blur(function() {
            if (!$(this).val()) {
                $(this).hide().prev().show();
            }
        });
    } else if ($(this).hasClass('default')) {
        $(this).removeClass('default').val('');
    }
}).blur(function() {
    addInput($(this));
});

function addInput($that) {
    var title = $that.attr('title');
    if (title && !$that.val()) {
        $that.addClass('default').val(title);
    }
}

function flToggle(that) {//显示或隐藏浮动选择项
    if ($(that).hasClass('show')) {
        $(that).removeClass('show');
    } else {
        $(that).addClass('show');
    }
    var $that = $(that).next();
    $that.toggle();
}

function showHide(that, obj) {//显示隐藏内容
    if ($(that).hasClass('show')) {
        $(that).removeClass('show');
    } else {
        $(that).addClass('show');
    }

    if (typeof obj == 'object') {
        obj.toggle();
    } else if (typeof obj == 'string') {
        $('.' + obj).toggle();
    }
}

function showPwd(that, pwd) {//显示密码
    var $that = $(that);
    var $box = $that.parent();
    var $ipt = $box.find("input[type='text']");
    var $pwd = $box.find("input[type='password']");

    $box.find('input').off('focus').off('blur');

    if ($ipt[0].style.display == 'none') {
        $that.html('隐藏密码').attr('title', 'ipt');
        $pwd.hide();
        $ipt.attr('id', pwd);
        $pwd.attr('id', '');
        $ipt.show().val($pwd.val());
    } else if ($pwd[0].style.display == 'none') {
        $that.html('显示密码').attr('title', 'pwd');
        if (!$ipt.val() || ($ipt.val() == $ipt.attr('title'))) {
            $ipt.val('');
        }
        $ipt.attr('id', '');
        $pwd.attr('id', pwd);
        $ipt.hide();
        $pwd.show().val($ipt.val());
    }
}


igoObj.setAuto = function(that) {//登录页，自动登录按钮；隐私设置;协议
    var $that = $(that).find('font');
    if ($that.hasClass('not')) {
        $that.removeClass('not');
    } else {
        $that.addClass('not');
    }
}

function pop(msg, mtype, but1, but2, fun1, fun2) {//弹出层
    //msg:文本信息
    //mtype:弹层类型	0:文字靠左显示		1:文字居中显示
    //but1:按钮一文字
    //but2:按钮二文字
    //fun1:按钮一方法
    //fun2:按钮二方法

    var top = document.body.scrollTop || document.documentElement.scrollTop;
    var h = document.body.scrollHeight > windowH ? document.body.scrollHeight : windowH;

    mtype = mtype ? mtype : 0;

    if ($('#pop')[0]) {
        var $text = $('#pop .text');
        var butInfo = but1 ? "<span onclick='" + fun1 + "'>" + but1 + "</span>" : '';
        if (mtype) {
            if (!$text.hasClass('center')) {
                $text.addClass('center');
            }
        } else {
            $text.removeClass('center');
        }

        $('#pop .text').html(msg);

        if (but2) {
            butInfo += "<span onclick=" + fun2 + ">" + but2 + "</span>";
        }

        if (butInfo) {
            if ($('#pop .op')[0]) {
                $('#pop .op').html(butInfo);
            } else {
                $('#pop .cn').append("<div class='op'>" + butInfo + "</div>");
            }
        } else {
            $('#pop .op').remove();
        }

        if (arguments.length > 2) {
            $('#pop .cn').removeClass('c2');
            $('#pop .close').remove();
        }

    } else {
        var className = "text";
        var butInfo = but1 ? "<span onclick=" + fun1 + ">" + but1 + "</span>" : '';
        if (mtype) {
            className = "text center";
        }
        if (but2) {
            butInfo += "<span onclick=" + fun2 + ">" + but2 + "</span>";
        }

        var htm = "<section id='pop'>";
        if (arguments.length <= 2) {
            htm += "<div class='cn c2'>";
            htm += "<span class='close' onclick='popclose()' id='close_btn'></span>";
        } else {
            htm += "<div class='cn'>";
        }
        htm += "<p class='" + className + "'>" + msg + "</p>";
        if (butInfo) {
            htm += "<div class='op'>";
            htm += butInfo;
            htm += "</div>";
        }
        htm += "</div>";
        htm += "</section>";

        if (!$('#shadow')[0]) {
            htm += "<div id='shadow'></div>";
        }

        $('body').append(htm);
    }

    var tp = $('#pop').height();
    var hb = document.documentElement.clientHeight;
    tp = (hb - tp) / 2;
    tp = tp >= 0 ? tp : 0;
    tp += top;

    $('#shadow').height(h);
    $('#pop').css('top', tp);

    $('#pop,#shadow').show();
}
function popshow(name) {//特殊弹出层
    if (!$('#shadow')[0]) {
        $('body').append("<div class='shadow'></div>");
    }

    name = '.' + name;
    var top = document.body.scrollTop || document.documentElement.scrollTop;
    var h = $('body').height();
    var tp = $(name).height();
    var hb = document.documentElement.clientHeight;

    tp = (hb - tp) / 2;
    tp = tp >= 0 ? tp : 0;
    tp += top;

    $('#shadow').height(h);
    $(name).css('top', tp);

    $('#shadow,' + name).show();
}

function popclose() {//弹出层关闭
    $('#pop,.pop,#shadow').hide();
}

/*---添加到桌面---*/
function addToHome() {
    var ua = window.navigator.userAgent;
    var nav = window.navigator;

    var isOther = (/ucbrowser|ucweb|qq/i).test(ua);
    if (isOther) {
        return 0;
    }

    var isIOS = (/iphone|ipod|ipad/i).test(ua);

    if (isIOS && window.localStorage) {
        if ((/os 7_|os 8_/i).test(ua)) {
            var img = "<img width='19' height='27' src='http://img01.51jobcdn.com/im/jc/image/stt_icon.png' alt='' />";
        } else if ((/os 6_/i).test(ua)) {
            var img = "<img width='25' height='25' src='http://img01.51jobcdn.com/im/jc/image/stt_icon2.png' alt='' />";
        } else {
            return 0;
        }

        var htm = "<div id='STT' class='bb'><div class='scn'><img class='cl' onclick='addToHome_close()' width='14' height='14' src='http://img01.51jobcdn.com/im/jc/image/close.png' alt='' /><p class='p1'><img width='60' height='60' src='http://img01.51jobcdn.com/im/mobile/m/logo_114.png' alt='' /><br />无忧招聘</p><p class='p2'>点击" + img + ",可以将图标添加到桌面哟~</p></div></div>";

        if (!localStorage.addToHome_tm) {
            localStorage.addToHome_tm = 0;
        }

        var s_tm = localStorage.addToHome_tm;

        if (s_tm == 0) {
            $('body').append(htm);
            setTimeout(function() {
                $('#STT').css({'bottom': 0, 'opacity': 1});
            }, 100);
        }
    }
}

function addToHome_close() {
    localStorage.addToHome_tm = 1;
    $('#STT').remove();
}

function getScrollTop() {
    var top = $('body').scrollTop();
    markST = 0;
    if (top) {
        markST = 1;
        return top;
    } else if (document.documentElement.scrollTop) {
        markST = 2;
        return document.documentElement.scrollTop;
    } else {
        markST = 3;
        return 0;
    }
}

function setScrollTop() {
    var val = arguments[0] || pLoadTop;
    if (markST == 1) {
        $('body').scrollTop(val);
    } else if (markST == 2) {
        document.documentElement.scrollTop = val;
    } else if (markST == 3) {
        $('body').scrollTop(val);
        document.documentElement.scrollTop = val;
    }
}

function pLoad(page, that) {//页面加载
    pLoadTop = getScrollTop() || 0;

    var $pobj = $('#' + page);
    var $that = $(that).parents('.pgbox');


    if ($pobj[0]) {
        $('.pgbox').hide();
        setScrollTop(0);
        $pobj.show();
    } else {
        var id = $that.attr('id');
        var h = $('body').height();
        var t = document.body.scrollTop || document.documentElement.scrollTop;
        t = (window.screen.height - 120) / 2 + t;

        if (!$('#shadow')[0]) {
            $('body').append("<div id='shadow' style='height:" + h + "px'></div>");
        } else {
            $('#shadow').height(h);
        }
        if (!$('#loading')[0]) {
            $('body').append("<div id='loading' style='top:" + t + "px'><span>Loading<em>...</em></span></div>");
        } else {

        }
        $('#shadow,#loading').show();

        $.ajax({
            url: page + '.php',
            timeout: 1000,
            success: function(data) {
                var htm = "<div id='" + page + "' class='pglox pgbox' title='" + id + "' style='z-index:20'>" + data + "</div>";
                $('body').append(htm);
                setTimeout(function() {
                    $('body').scrollTop(0);
                    $('.pgbox').hide();
                    $that.hide();
                    $('#' + page).show();
                    $('#shadow,#loading').hide();
                }, 500);

            },
            error: function(xhr, errorType, error) {
                if (errorType == 'timeout') {
                    alert('服务器等待超时！');
                } else if (errorType == 'error' && error == 'Not Found') {
                    alert('未找到服务器文件！');
                }
                $('#shadow,#loading').hide();
            }
        });
    }
}

function timeClock(id, num) {
    var that = document.getElementById(id);
    var num = num ? num : 60;
    var fID = setInterval(setBut, 1000);

    that.setAttribute('class', 'gray');

    function setBut() {
        if (num > 0) {
            that.innerHTML = num + '秒后重新发送';
            num--;
        } else {
            that.innerHTML = '重新发送校验码';
            that.setAttribute('class', '');
            clearInterval(fID);
        }
    }
}

$('.back').bind('click', function() {//返回
    if (!$(this).attr('href')) {
        var $pName = $(this).parents('.pgbox');
        var $that = $pName.attr('title');
        $that = $('#' + $that);
        $pName.css('z-index', '7').hide();
        $that.show();

        setScrollTop();
    }
});

$('.cinfo').each(function() {//公司介绍，显示更多
    if ($(this).find('p').height() > 120) {
        $(this).parent().find('.more').css('display', 'inline-block');
    }
});

$('.more').click(function() {//公司介绍，显示更多
    var $that = $(this).parents('.cmbox').find('.cinfo');
    if ($that.height() > 120) {
        $(this).html('查看全部').removeClass('mk');
        $that.css('max-height', 120);
    } else {
        $(this).html('收起内容').addClass('mk');
        $that.css('max-height', 'none');
    }
});

$('.i_add').click(function() {//招聘人数增加
    var $that = $(this).parent().find('input');
    var num = $that.val() ? $that.val() : 0;
    var num = parseInt(num);
    if (num == '999') {
        return false;
    }
    num++;
    $that.val(num);
});

$('.i_sub').click(function() {//招聘人数减少
    var $that = $(this).parent().find('input');
    var num = $that.val() ? $that.val() : 0;
    var num = parseInt(num);

    if (num > 1) {
        num--;
        $that.val(num);
    }
});

$('.slet select').change(function() {//下拉框取值
    var v = '';
    $(this).find('option').each(function() {
        if ($(this).attr('selected') == true) {
            v = $(this).html();
            return false;
        }
    });
    $(this).siblings().html(v);
});
$('.bb select').change(function() {//下拉框取值
    var v = '';
    $(this).find('option').each(function() {
        if ($(this).attr('selected') == true) {
            v = $(this).html();
            return false;
        }
    });
    $(this).siblings().html(v);
});

$(function() {
    windowH = window.innerHeight;//浏览器显示区域大小
});


/*
 *
 * 页面链接，临时
 * 
 */
function jmp(name) {
    window.location.href = name + '.php';
}


function tpimg() {
    window.location.href = '图片展示.php';
}

function back() {
    window.history.go(-1);
}

/*---图片展示---*/
function fSwiper(n, c) {
    var num = swiperImg.length;
    var boxH = windowH - 58;
    document.body.scrollTop = 0;

    if ($('#js_swiper')[0]) {
        mySwiper.swipeTo(n, 0);
        $('#shadow,#js_swiper').show();
    } else {
        var htm = "<div id='js_swiper'>";
        htm += "<p class='pt'>";
        for (var i = 0; i < num; i++) {
            htm += "<span></span>";
        }
        htm += "<em onclick='swiperClose()'>关闭</em>";
        htm += "</p>";
        htm += "<div class='swiper_box'>";
        htm += "<span class='prev' onclick='mySwiper.swipePrev()' style='top:" + (boxH / 2 - 30) + "px'></span><span class='next' onclick='mySwiper.swipeNext()' style='top:" + (boxH / 2 - 30) + "px'></span>";
        htm += "<div class='swiper-container' style='height:" + boxH + "px'>";
        htm += "<div class='swiper-wrapper'>";
        for (var i = 0; i < num; i++) {
            htm += "<div class='swiper-slide' style='color:red;height:" + boxH + "px'>";
            htm += "<img width='40' height='40' style='margin-top:" + (boxH / 2 - 50) + "px' src='http://img01.51jobcdn.com/im/iehire/image/loading.gif' alt='loading' />";
            htm += "<span style='display:none' title='" + swiperImg[i] + "'></span>";
            htm += "</div>";
        }
        htm += "</div>";
        htm += "</div>";
        htm += "</div>";
        htm += "</div>";

        if (!$('#shadow')[0]) {
            htm += "<div id='shadow'></div>";
        }

        $('body').append(htm);

        mySwiper = $('.swiper-container').swiper({
            mode: 'horizontal',
            loop: true,
            onSlideChangeStart: function(swiper) {
                var that = mySwiper.activeSlide();
                var index = mySwiper.activeIndex;

                if (index == 0) {
                    index = num - 1;
                } else if (index > num) {
                    index = 0;
                } else {
                    index--;
                }
                $('#js_swiper .pt span').removeClass('mk').eq(index).addClass('mk');

                loadImg(that);
            }
        });
        if (c == '' || c == 1) {
            $('#js_swiper p span').css('display', 'none');
            $('#js_swiper .swiper_box span').css('display', 'none');
        }

        fSwiper(n);
    }
}

function loadImg(that) {
    var $that = $(that);
    var $img = $that.find('img');

    function setBox(img) {
        if (img.width <= 300) {
            var h = img.height;
        } else {
            var h = parseInt(img.height * 300 / img.width);
        }

        if (h > windowH) {
            $that.height(h);
            $('.swiper-container').height(h);
        }
    }

    if ($img.attr('alt') != 'loading') {
        setBox($img[0]);
        return 0;
    }

    var src = $that.find('span').attr('title');
    var img = new Image();
    img.src = src;

    img.onload = function() {
        $img.removeAttr('width').removeAttr('height').removeAttr('style').attr('src', src).attr('alt', '');

        setBox(img);
    }
}

function swiperClose() {
    $('#shadow,#js_swiper').hide();
}

var wSave = {//表单数据存储
    name: '',
    time: ''
};
wSave.ini = function(name) {
    if (window.sessionStorage) {
        wSave.name = 'wSave_' + name;

        if (sessionStorage[wSave.name]) {
            wSave.get();
        }
        wSave.set();
    }
};
wSave.set = function() {
    var result = {};
    var el = {
        'input': $("input[type='text']"),
        'select': $("select"),
        'textarea': $("textarea")
    }
    for (k in el) {
        result[k] = {};
        el[k].each(function() {
            var name = $(this).attr('name');
            var title = $(this).attr('title');
            var value = $(this).val();
            if (name && title != value) {
                result[k][name] = $(this).val();
            }
        });
    }

    result = JSON.stringify(result) || '';
    sessionStorage.setItem(wSave.name, result);
};
wSave.get = function() {
    var result = {};
    console.log(sessionStorage[wSave.name])
};
